/*
 *  MilovoRandom.cpp
 *  Milovo04alfa00
 *
 *  Created by Luca on 05/11/06.
 *  Copyright 2006 __MyCompanyName__. All rights reserved.
 *
 */

#include "MilovoRandom.h"

MilovoRandom::MilovoRandom()
{
	FlagAllert = false;
}

Mil_Int MilovoRandom::GetIntRandom(Mil_Int tmpFromNum, Mil_Int tmpToNum)
{
	// if parameters passed to this function are negative
	// this function exit with failure
	if((tmpFromNum < 0) || (tmpToNum < 0))
	{
		cout << "tmpFromNum: " << tmpFromNum << "\ttmpToNum: " << tmpToNum << "\tCannot generate a number with negative numbers" << endl;
		exit(EXIT_FAILURE);
	}
	// if tmpToNum is minor of tmpFromNum this 
	// function exit with failure
	if(tmpToNum < tmpFromNum)
	{
		cout << "tmpToNum (" << tmpToNum << ") is < of tmpFromNum (" << tmpFromNum << ") ... Cannot generate a number with a negative delta" << endl;
		exit(EXIT_FAILURE);
	}
	
	Mil_Int Result = randInt((tmpToNum - tmpFromNum)) + tmpFromNum;
	// if the random outcome in Result variable is out of the boundaries passed by parameters
	// the function exit with failure
	if((Result < tmpFromNum) || (Result > tmpToNum))
	{
		cout << "Result: " << Result << "\tGenerate a number out of boundaries" << endl;
		exit(EXIT_FAILURE);
	}
	return(Result);
}

Mil_Double MilovoRandom::GetDoubleRandom(Mil_Double tmpFromNum, Mil_Double tmpToNum)
{
	// if parameters passed to this function are negative
	// this function exit with failure
	if((tmpFromNum < 0) || (tmpToNum < 0))
	{
		cout << "tmpFromNum: " << tmpFromNum << "\ttmpToNum: " << tmpToNum << "\tCannot generate a number with negative numbers" << endl;
		exit(EXIT_FAILURE);
	}
	// if tmpToNum is minor of tmpFromNum this 
	// function exit with failure
	if(tmpToNum < tmpFromNum)
	{
		cout << "tmpToNum (" << tmpFromNum << ") is < of tmpFromNum (" << tmpToNum << ") ... Cannot generate a number with a negative delta" << endl;
		exit(EXIT_FAILURE);
	}
	
	Mil_Double Result = rand((tmpToNum - tmpFromNum)) + tmpFromNum;
	// if the random outcome in Result variable is out of the boundaries passed by parameters
	// the function exit with failure
	if((Result < tmpFromNum) || (Result > tmpToNum))
	{
		cout << "Result: " << Result << "\tGenerate a number out of boundaries" << endl;
		exit(EXIT_FAILURE);
	}
	return(Result);
}

